import 'package:seedfour/generated/json/base/json_convert_content.dart';
import 'package:seedfour/app/models/message_list_entity.dart';

MessageListEntity $MessageListEntityFromJson(Map<String, dynamic> json) {
  final MessageListEntity messageListEntity = MessageListEntity();
  final int? total = jsonConvert.convert<int>(json['total']);
  if (total != null) {
    messageListEntity.total = total;
  }
  final List<MessageData>? data = (json['data'] as List<dynamic>?)?.map(
          (e) => jsonConvert.convert<MessageData>(e) as MessageData).toList();
  if (data != null) {
    messageListEntity.data = data;
  }
  return messageListEntity;
}

Map<String, dynamic> $MessageListEntityToJson(MessageListEntity entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['total'] = entity.total;
  data['data'] = entity.data.map((v) => v.toJson()).toList();
  return data;
}

extension MessageListEntityExtension on MessageListEntity {
  MessageListEntity copyWith({
    int? total,
    List<MessageData>? data,
  }) {
    return MessageListEntity()
      ..total = total ?? this.total
      ..data = data ?? this.data;
  }
}

MessageData $MessageDataFromJson(Map<String, dynamic> json) {
  final MessageData messageData = MessageData();
  final int? id = jsonConvert.convert<int>(json['id']);
  if (id != null) {
    messageData.id = id;
  }
  final int? type = jsonConvert.convert<int>(json['type']);
  if (type != null) {
    messageData.type = type;
  }
  final int? createdAt = jsonConvert.convert<int>(json['createdAt']);
  if (createdAt != null) {
    messageData.createdAt = createdAt;
  }
  final String? title = jsonConvert.convert<String>(json['title']);
  if (title != null) {
    messageData.title = title;
  }
  final String? content = jsonConvert.convert<String>(json['content']);
  if (content != null) {
    messageData.content = content;
  }
  final String? orderId = jsonConvert.convert<String>(json['orderId']);
  if (orderId != null) {
    messageData.orderId = orderId;
  }
  final int? readStatus = jsonConvert.convert<int>(json['readStatus']);
  if (readStatus != null) {
    messageData.readStatus = readStatus;
  }
  return messageData;
}

Map<String, dynamic> $MessageDataToJson(MessageData entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['id'] = entity.id;
  data['type'] = entity.type;
  data['createdAt'] = entity.createdAt;
  data['title'] = entity.title;
  data['content'] = entity.content;
  data['orderId'] = entity.orderId;
  data['readStatus'] = entity.readStatus;
  return data;
}

extension MessageDataExtension on MessageData {
  MessageData copyWith({
    int? id,
    int? type,
    int? createdAt,
    String? title,
    String? content,
    String? orderId,
    int? readStatus,
  }) {
    return MessageData()
      ..id = id ?? this.id
      ..type = type ?? this.type
      ..createdAt = createdAt ?? this.createdAt
      ..title = title ?? this.title
      ..content = content ?? this.content
      ..orderId = orderId ?? this.orderId
      ..readStatus = readStatus ?? this.readStatus;
  }
}